﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FrbaBus.CompraProducto;
using FrbaBus.ConsultaPuntos;

namespace FrbaBus.IngresoCliente
{
    public partial class FormActualizarDatosCliente : Form
    {
        private string referer;

        public FormActualizarDatosCliente(string referer)
        {
            InitializeComponent();
            CargarCombos();
            this.referer = referer;
        }

        private void CargarCombos() {

            cbSexo.Items.Insert(0, "M");
            cbSexo.Items.Insert(1, "F");
            this.cbSexo.SelectedIndex = 0;


            cbDiscapacitado.Items.Insert(0, "No");
            cbDiscapacitado.Items.Insert(1, "Si");
            this.cbDiscapacitado.SelectedIndex = 0;
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            actualizarDatosFaltantes(Cliente.clientId);

            this.Hide();

            if (this.referer == "compra")
            {
                FormCompraProducto form = new FormCompraProducto(long.Parse(Cliente.clientId));
                form.ShowDialog(this);
            }
            if (this.referer == "consulta")
            {
                FormConsultarPuntos form = new FormConsultarPuntos();
                form.ShowDialog(this);
            }
            if (this.referer == "canje")
            {

            }
       
        }

        private void actualizarDatosFaltantes(string DNI) {

            string query = "";

            string sexo =  this.cbSexo.Items[this.cbSexo.SelectedIndex].ToString();

            int discapacitado = this.cbDiscapacitado.SelectedIndex;

            query = "UPDATE THE_BEST_IAS.clientes SET cli_sexo = '" + sexo + "', cli_discapacitado = " + discapacitado;
            query += " WHERE usu_codigo = " + DNI;

            DbHelper.ExecuteNonQuery(query);

        }
    }
}
